package l1j.server.server.model.clan;

import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.server.GeneralThreadPool;
import l1j.server.server.utils.TimeUtil;

public class HouseDeadlineTimer implements Runnable {
	private static Logger _log = Logger.getLogger(HouseDeadlineTimer.class.getName());
	
	public static void initilize() {
		GeneralThreadPool.getInstance().execute(new HouseDeadlineTimer());
	}

	private HouseDeadlineTimer() {

	}

	public void run() {
		while (true) {
			try {
				Thread.sleep(60 * 1000);
				for(int i : L1HouseLocation._houseIds){
					ClanHouse house = ClanHouse.getHouseById(i);
					Calendar calNow = TimeUtil.getCalendar();
					Calendar calHouse = TimeUtil.timestampToCalendar(house.getDeadLine());
					if(calHouse.before(calNow)){
						house.sellHouse();
					}
				}
			} catch (Exception e) {
				_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
			}
		}
	}
}
